

#pragma once

#include <cocos2d.h>
#include <string>
#include <vector>

using namespace std;
using namespace cocos2d;

class FrameAnimation : public Sprite {
public:
	FrameAnimation(void);
	virtual ~FrameAnimation(void);
    
public:
	float frameRate;
	float frameRateFactor;
	float elapsedTime;

	int frameIndex ;
	int frameCount;

	bool isLoop ;
	bool paused ;
	bool finished;
    
    string key;

public:
    void setLogicPosition(const Point& pos);

    Point getLogicPosition() {
        return _logicPosition;
    }

	void set(const string& animKey, float rate, const vector<string>& frames);
	void setFrame(int index);
    void update (float ticks);
    
	inline void restart (){
		frameIndex = 0;
		finished = false;
		paused = false;
        
        setFrame(0);
	}

private:
	Point _logicPosition;
	vector<string> _frames;
};

class AnimationSequence {
public:
	AnimationSequence(int id);

	~AnimationSequence();

	bool isFinished();

	void playFirst();

	void playNext();

	void update (float ticks);

	void add(FrameAnimation* anim, bool needLoop, float _arrDurations);

	int getCount() {
		return _arrAnims.size();
	}

public:
	int id;
	int playingAnimIndex;

	Node* parent;

private:
	vector<FrameAnimation*> _arrAnims;
	vector<bool> _arrLoops;
	vector<float> _arrDurationss;

	float _timeElapsed;


};

